﻿using BCCommon;
using BCDto.OA.BusinessFlowRecord;
using BCService.OA.BusinessFlowRecord;
using BCService.Utils;
using BlackCoffeeRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlackCoffeeRESTful.Controllers.Management.OA.BusinessFlowRecord
{
    /// <summary>
    /// OA系统业务流记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BusinessFlowRecordController : ManagementBaseController
    {
        private readonly IBusinessFlowRecordService businessFlowRecordService;

        public BusinessFlowRecordController(IBusinessFlowRecordService businessFlowRecordService)
        {
            this.businessFlowRecordService = businessFlowRecordService;
        }

        #region 添加OA系统业务流记录
        /// <summary>
        ///  添加OA系统业务流记录
        /// </summary>
        /// <param name="requestDto">OA系统业务流记录信息</param>
        /// <response code="201">添加OA系统业务流记录成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统业务流记录")]
        [ProducesResponseType(typeof(BusinessFlowRecordDto), 201)]
        public IActionResult Post(
            [FromBody]BusinessFlowRecordRequestDto requestDto)
        {
            var result = this.businessFlowRecordService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/BusinessFlowRecord/{0}", result.BusinessFlowRecordId), result);
        }
        #endregion

        #region 修改OA系统业务流记录
        /// <summary>
        ///  修改OA系统业务流记录
        /// </summary>
        /// <param name="businessFlowRecordId">OA系统业务流记录Id</param>
        /// <param name="requestDto">OA系统业务流记录信息</param>
        /// <response code="200">修改OA系统业务流记录成功</response>
        /// <returns></returns>
        [HttpPut("{business_flow_record_id}")]
        [Log("修改OA系统业务流记录")]
        [ProducesResponseType(typeof(BusinessFlowRecordDto), 200)]
        public IActionResult Put([FromRoute(Name = "business_flow_record_id")]long businessFlowRecordId, [FromBody]BusinessFlowRecordRequestDto requestDto)
        {
            BusinessFlowRecordPutDto putDto = requestDto.As<BusinessFlowRecordPutDto>();
            putDto.BusinessFlowRecordId = businessFlowRecordId;
            return this.Ok(this.businessFlowRecordService.Update(putDto));
        }
        #endregion

        #region 删除OA系统业务流记录
        /// <summary>
        ///  删除OA系统业务流记录
        /// </summary>
        /// <param name="businessFlowRecordId">OA系统业务流记录Id</param>
        /// <response code="204">删除OA系统业务流记录成功</response>
        /// <returns></returns>
        [HttpDelete("{business_flow_record_id}")]
        [Log("删除OA系统业务流记录")]
        public IActionResult Delete([FromRoute(Name = "business_flow_record_id")]long businessFlowRecordId)
        {
            this.businessFlowRecordService.Delete(businessFlowRecordId);
            return this.NoContent();
        }
        #endregion

        #region 获取OA系统业务流记录
        /// <summary>
        ///  获取OA系统业务流记录
        /// </summary>
        /// <param name="businessFlowRecordId">OA系统业务流记录Id</param>
        /// <response code="200">获取OA系统业务流记录</response>
        /// <returns></returns>
        [HttpGet("{business_flow_record_id}")]
        [ProducesResponseType(typeof(BusinessFlowRecordDto), 200)]
        public IActionResult Get([FromRoute(Name = "business_flow_record_id")]long businessFlowRecordId)
        {
            return this.Ok(this.businessFlowRecordService.GetEntity(businessFlowRecordId));
        }
        #endregion

        #region 获取OA系统业务流记录列表
        /// <summary>
        ///  获取OA系统业务流记录列表
        /// </summary>
        /// <response code="200">获取OA系统业务流记录列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(BusinessFlowRecordDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.businessFlowRecordService.GetList());
        }
        #endregion

        #region 获取OA系统业务流记录（分页）
        /// <summary>
        ///  获取OA系统业务流记录（分页）
        /// </summary>
        /// <param name="businessFlowModelCode">业务流模型编码</param>
        /// <param name="referenceNo">引用编号</param>
        /// <param name="isInitialized">已初始化完成的</param>
        /// <param name="isInitFailed">初始化失败的</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统业务流记录（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BusinessFlowRecordDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "business_flow_model_code")]string businessFlowModelCode,
            [FromQuery(Name = "reference_no")]string referenceNo,
            [FromQuery(Name = "is_initialized")]bool? isInitialized,
            [FromQuery(Name = "is_initFailed")]bool? isInitFailed,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.businessFlowRecordService.Query(businessFlowModelCode,referenceNo,isInitialized ,isInitFailed, start, end, pageIndex, pageSize));
        }
        #endregion
    }
}
